/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 16:06:20
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-04-23 17:30:13
 */
import { uploadType,regularRule, getAreaObj,getBaseAreaData,formateDate } from '@/utils/util'
import { getStore } from '@/utils/store'
import { cloneDeep } from 'lodash-es'
import { format } from 'path'
import { detailConfig } from '@/views/datacenter/business/elderlyInstitutionsRating/config'

let isUploadDic = [
	{label:"全部",value:"",type:"primary"},
	{label:"未上传",value:"0",type:"danger"},
	{label:"已上传",value:"1",type:"success"}
]
let currentYear = String(new Date().getFullYear())
// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '归属年份', prop: 'belongYear' },
		{ label: '老人姓名', prop: 'name' },
		{ label: '身份证号', prop: 'idCard',plusXing: '2,2' },
		{
			label: '手机号码',
			prop: 'telephone',
            plusXing: '2,2'
		},
		{
			label: '改造地址',
			prop: 'implementationAddress',
		},
		{
			label: '施工单位',
			prop: 'implementationUnitName',
		},
		{
			label: '施工现场负责人',
			prop: 'implementationDirector',
		},
		{
			label: '施工现场负责人联系方式',
			prop: 'implementationDirectorPhone',
		},
		{
			label: '施工竣工时间',
			prop: 'implementationTime',
		},
		// {
		// 	label: '总金额',
		// 	prop: 'implementationTotalCost',
		// },
		{
			label: '改造验收表',
			prop: 'acceptanceResultFile1',
		},
		{
			label: '改造验收表上传情况',
			prop: 'isWithMaterial',
			custome:"tag",
			dicData:isUploadDic
		},
		{
			label: '验收时间',
			prop: 'acceptanceTime',
		},
		{
			label: '验收人',
			prop: 'acceptanceDirector',
		},
		{
			label: '验收机构',
			prop: 'acceptanceUnitName',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

const formConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	column:[
		{
			label:"老人姓名",
			prop:"name",
			propName:"name",
            type: 'autoSelect',
			api: 'view_bscAdaptOldImplementation_page',
			filterKey: 'name',
			filterLabel: 'name',
			multiple: false,
            // paramsObj: {
				// roleName: '安全员',
			// },
			change:(item, form, value)=>{
				form.idCard = item.idCard
				form.telephone = item.telephone
				form.provinceId = item.provinceId
				form.provinceName = item.provinceName
				form.areaId = item.areaId
				form.areaName = item.areaName
				form.cityId = item.cityId
				form.cityName = item.cityName
				form.streetId = item.streetId
				form.streetName = item.streetName
				form.communityId = item.communityId
				form.communityName = item.communityName

				form.crProvinceId = item.crProvinceId
				form.crProvinceName = item.crProvinceName
				form.crAreaId = item.crAreaId
				form.crAreaName = item.crAreaName
				form.crCityId = item.crCityId
				form.crCityName = item.crCityName
				form.crStreetId = item.crStreetId
				form.crStreetName = item.crStreetName
				form.crCommunityId = item.crCommunityId
				form.crCommunityName = item.crCommunityName
				form.crAddress = item.crAddress
				form.address = item.address
				form.mainId = item.mainId
				form.implementationAddress = item.implementationAddress
				form.implementationTime = item.implementationTime
				form.implementationUnitName = item.implementationUnitName
				form.implementationTotalCost = item.implementationTotalCost
			},
			span:24,
			rules:[
				{required:true,message:"请填写老人姓名"}
			]
		},
		{
			label:"身份证号",
			prop:"idCard",
			disabled:true,
			// rules:[
			// 	{required:true,pattern:regularRule.idCard,message:"请填写身份证号"}
			// ],
			span:12
		},
        {
			label:"改造地址",
			disabled:true,
			prop:"implementationAddress",
			span:12,
			// rules:[
			// 	{required:true,message:"请填写改造地址"}
			// ]
		},
		{
			label:"手机号码",
			prop:"telephone",
			disabled:true,
			span:12,
			// rules:[
			// 	{required:true,pattern:regularRule.phone,message:"请填写手机号码"}
			// ]
		},
		{
			label:"施工单位",
			disabled:true,
			prop:"implementationUnitName",
			span:12,
			// rules:[
			// 	{required:true,message:"请填写施工单位"}
			// ]
		},
		{
			label:"施工现场负责人",
			prop:"implementationDirector",
			span:12,
			rules:[
				{required:true,message:"请填写施工现场负责人"}
			]
		},
		{
			label:"施工现场负责人联系方式",
			prop:"implementationDirectorPhone",
			span:12,
			rules:[
				{required:true,pattern:regularRule.phone,message:"请填写施工现场负责人联系方式"}
			]
		},
        // {
		// 	label:"施工开工时间",
        //     type:'date',
        //     format: 'YYYY年MM月DD',
        //     valueFormat: 'YYYY-MM-DD',
		// 	prop:"implementationStartTime",
		// 	span:24,
		// 	rules:[
		// 		{required:true,message:"请填写施工开工时间"}
		// 	]
		// },
        {
			label:"施工竣工时间",
            type:'date',
			disabled:true,
            format: 'YYYY年MM月DD',
            valueFormat: 'YYYY-MM-DD',
			prop:"implementationTime",
			span:24,
			// rules:[
			// 	{required:true,message:"请填写施工竣工时间"}
			// ]
		},
		{
			label:"验收时间",
            type:'date',
            format: 'YYYY年MM月DD',
            valueFormat: 'YYYY-MM-DD',
			prop:"acceptanceTime",
			span:24,
			rules:[
				{required:true,message:"请填写验收时间"}
			]
		},
		{
			label:"验收人",
            type:'input',
			prop:"acceptanceDirector",
			span:24,
			rules:[
				{required:true,message:"请填写验收人"}
			]
		},
		{
			label:"验收机构",
            type:'input',
			prop:"acceptanceUnitName",
			span:24,
			rules:[
				{required:true,message:"请填写验收机构"}
			]
		},
		{
			label:"适老化改造项目归属年份",
			prop:"belongYear",
			type:"year",
			format:'YYYY年',
			valueFormat:"YYYY",
			defaultValue:currentYear,
			span:12,
			rules:[
				{required:true,message:"请填写适老化改造项目归属年份"}
			]
		},
        {
            label:"适老化改造竣工图",
            type:'upload',
			// apiName: 'ost_uploadFile2',
			prop:"implementationFile",
			fileType:'image/png,image/jpg,image/jpeg',
            accept:'.png,.jpg,.jpeg',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			multiple: true,
			uploadTip:"上传文件（图片）",
			span:24,
			rules:[
				{required:true,message:"请上传适老化改造竣工图"}
			]
        },
		{
            label:"安装成功说明",
            type:'upload',
			// apiName: 'ost_uploadFile2',
			prop:"installationSuccessInstructions",
			fileType:'application/pdf,image/png,image/jpg,image/jpeg',
            accept:'.pdf,.png,.jpg,.jpeg',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			multiple: true,
			uploadTip:"上传文件（pdf、图片）",
			span:24,
			rules:[
				{required:true,message:"请上传安装成功说明"}
			]
        },
		{
            label:"适老化改造验收表",
            type:'upload',
			// apiName: 'ost_uploadFile2',
			prop:"acceptanceResultFile",
			fileType:'application/pdf,image/png,image/jpg,image/jpeg',
            accept:'.pdf,.png,.jpg,.jpeg',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			multiple: true,
			uploadTip:"上传文件（pdf、图片）",
			span:24,
			change:(item, form, value)=>{
				if(value){
					form.materialUploadTime = formateDate(new Date(),true)
				}else{
					form.materialUploadTime = ''
				}
				
			},
			rules:[
				{required:true,message:"请上传适老化改造验收表"}
			]
        },
		
	]
}
export const acceptFormConfig =  formConfig
export const api = {
	index: 'view_bscAdaptOldAcceptance_page',
	add: 'view_bscAdaptOldAcceptance_add',
	detail:"view_bscAdaptOldAcceptance_view",
	edit: 'view_bscAdaptOldAcceptance_edit',
	delete: 'view_bscAdaptOldAcceptance_del',
	export:'view_bscAdaptOldAcceptance_export',
	import:'view_bscAdaptOld_acceptance_import'
}

export const baseConfig = {
	pageName: '适老化改造验收管理',
	// 数据字典
	dictcodes: ['ACCESS_LEVEL_COUNTRY'],
	rowKey: 'id',
	tipLabel: 'name',
	addLabel: '新增',
	importLabel:'批量导入',
	api: {
		...api,
	},
	auth: {
		...api,
		mulitSet:'mulitSet',
	},
	paramsObj:{
		
	},
	// 当前行操作按钮
	menuBtn: [
		{
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	
		{
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth:api.edit,
			condition: "(row)=>(row.isEditDel)",
			text: true,
			show: true,
		},
		{
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: api.delete,
			condition: "(row)=>(row.isEditDel)",
			text: true,
			show: true,
		}
	],
	detailConfig:formConfig,
	importConfig :{
		tabSteps: [
			{
				label: '下载模板',
				download: '下载模板',
				active: 1,
				rules: [
					{
						label: '下载最新导入模板。共1个：',
						children: [
							{
								label: '《适老化改造验收信息表》',
								link: true,
								url: 'view_bscAdaptOld_acceptance_downloadTemplate',
							},
						],
					},
				],
			},
			{
				label: '导入《适老化改造验收信息表》',
				description: '',
				uploadTip: '适老化改造验收信息表',
				active: 2,
				url: 'view_bscAdaptOld_acceptance_import',
				code: 4009,
				rules: [
					{
						label: '导入规则说明:',
						children: [
							{
								label: '(1)导入模式为“覆盖导入”，待导入的适老化改造验收信息表会覆盖平台已存在的',
							},
						],
					},
				],
			},
		],
	},
	formConfig,
	dialogConfig: {
		width: '80%',
	},
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{ label: '老人姓名', prop: 'name', type: 'input', span: 8 },
			{ label: '身份证号', prop: 'idCard', type: 'input', span: 8 },
			{
				label: '手机号码',
				prop: 'telephone',
				span: 8,
			},
			{
				label: '改造地址',
				prop: 'implementationAddress',
				span: 8,
			},
			{
				label: '施工单位',
				prop: 'implementationUnitName',
				span: 8,
			},
			{
				label: '施工现场负责人',
				prop: 'implementationDirector',
				span: 8,
			},
			{
				label: '施工负责人联系方式',
				prop: 'implementationDirectorPhone',
				span: 8,
			},
			{
				label: '验收机构',
				prop: 'acceptanceUnitName',
				span: 8,
			},
			{
				label: '改造验收表上传情况',
				prop: 'isWithMaterial',
				type: 'select',
				dicData:isUploadDic,
				span: 8,
			},
			// {
			// 	label: '验收状态',
			// 	prop: 'acceptanceResult',
			// 	propName:'acceptanceResultLabel',

			// 	span: 8,
			// },
			{
				label: '施工竣工时间',
				prop: 'implementationTimeBetween',
				type: 'daterange',
				format: 'YYYY年MM月DD',
				valueFormat: 'YYYY-MM-DD',
				span: 12,
			},
			{
				label: '验收时间',
				prop: 'acceptanceTimeBetween',
				type: 'daterange',
				format: 'YYYY年MM月DD',
				valueFormat: 'YYYY-MM-DD',
				span: 12,
			},
			
		],
	},
	// 列表
	tableConfig,
    saveFormate: async (form) => {
        let copyForm = cloneDeep(form)
		return new Promise((resolve, reject) => {
			resolve(copyForm)
		})
	},
	onLoadFormate: async (arr) => {
		let tableData = arr.map((item) => {
			
			if(item.acceptanceResultFile){
				item.isWithMaterial = '1'
			}else{
				item.isWithMaterial = '0'
			}
			item.acceptanceResultFile1 =item.acceptanceResultFile 
			// 处理编辑和删除控制
			let userInfo = getStore('userInfo')
			if(userInfo.classifyId==3){
				// 行政用户，用区域判断
				if(getBaseAreaData(item).myAreaId==getBaseAreaData(userInfo).myAreaId&&item.authOrganizationId==userInfo.organizationId){
					item.isEditDel = true
				}else{
					item.isEditDel = false
				}
			}else if(userInfo.classifyId==5){
				// 服务商
				if(item.authOrganizationId==userInfo.organizationId){
					item.isEditDel = true
				}else{
					item.isEditDel = false
				}
			}
			return item
		})
		return Promise.resolve(tableData)
	},
	beforeOnLoadFormate(form) {
		let copyForm = cloneDeep(form)
		// 处理搜索条件
		if(copyForm.implementationTimeBetween){
			copyForm.implementationTimeBetween[0]=copyForm.implementationTimeBetween[0]+' 00:00:00'
			copyForm.implementationTimeBetween[1]=copyForm.implementationTimeBetween[1]+' 23:59:59'
			copyForm.implementationTimeBetween = copyForm.implementationTimeBetween.join(',')
		}
		if(copyForm.acceptanceTimeBetween){
			copyForm.acceptanceTimeBetween = copyForm.acceptanceTimeBetween.join(',')
		}
		return new Promise((resolve, reject) => {
			resolve(copyForm)
		})
	},
}
